package com.lagou.rank;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class RankDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        //获取配置文件对象
        Configuration configuration = new Configuration();
        //获取job对象实例
        Job job = Job.getInstance(configuration, "RankDriver");

        //设置jar加载路径
        job.setJarByClass(RankDriver.class);

        //设置map和reduce类
        job.setMapperClass(RankMapper.class);
        job.setReducerClass(RankReducer.class);

        //设置map输出
        job.setMapOutputKeyClass(IntWritable.class);
        job.setMapOutputValueClass(NullWritable.class);

        //设置最终输出kv类型
        job.setOutputKeyClass(IntWritable.class);
        job.setOutputValueClass(IntWritable.class);

        //设置输入和输出路径
        FileInputFormat.setInputPaths(job, new Path("e:/input"));
        FileOutputFormat.setOutputPath(job, new Path("e:/output"));

        //提交
        boolean flag = job.waitForCompletion(true);

        System.exit(flag ? 0 : 1);

    }
}
